/*
 * File:   11833.cpp
 * Author: xerxes
 *
 * Created on September 18, 2011, 7:03 AM
 *
 * I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define pi pair< int , int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
#define fo( i, ed ) foR( i , 0 , ed )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define vp vector< pair<int,int> >

inline void wait(double seconds) {
    double endtime = clock()+(seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}
int N,M,C,K;
vector< vp > cango;
int costTable[251][251];

inline void Read() {
    fo(i,251){
        fo(j,251){
            costTable[i][j]=(int)1023456789;
        }
    }
    cango.assign(N, vp() );
    int x,y,c;
    fo(i,M){
        CI(x);
        CI(y);
        CI(c);
        cango[x].pb( mk(y,c) );
        cango[y].pb( mk(x,c) );
        costTable[x][y]=costTable[y][x]=c;
    }
}
int D[251];
int F[251];
int serviceRoute[251];
inline int dijkstra(int source, int sink){
    //initialized basic
    SET(F,0);
    fo(i,251){
        D[i]=(int)1023456789;
    }
    //---------------------------
    set< pi, less< pi > > pq;
               //dist, node
    pq.insert( mk(0,source) );
    D[source]=0;

    while( pq.empty()==false ){
        int father = pq.begin()->s;
        pq.erase( pq.begin() );
        if( F[father] )continue;
        if( serviceRoute[father] )continue;
        
        for(int i=0,j=SZ(cango[father]); i<j; ++i ){
            int child = cango[father][i].f;
            int ccost = cango[father][i].s;

            if( serviceRoute[ child ] ){
                continue;
            }
            if( F[child]==0 && D[father]+ccost < D[child] ){
                D[child]=D[father]+ccost;
                pq.insert( mk(D[child], child) );
            }
        }

        F[father]=1;
    }
    return D[sink];
}
inline int FlowServiceRoute(int source, int sink){
    int ccost=0;
    for(int i=source; i+1<sink;++i){
        ccost+= costTable[i][i+1];
    }
    return ccost;
}
inline void Proc(){
    SET(serviceRoute,0);
    for(int i=0;i<C;++i){
        serviceRoute[i]=1;
    }

    bool prothom=true;
    int best = 0;
    for(int i=0;i<C;++i){
        serviceRoute[i]=0;
        int d1 = dijkstra(K,i) + FlowServiceRoute(i,C);
        //printf("DISTANCE FROM %d TO %d = %d\n",K,i,d1);wait(1);
        serviceRoute[i]=1;
        if( prothom ){
            best = d1;
            prothom=false;
        }
        else{
            best = min( best, d1);
        }
    }
    cout<<best<<"\n";
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "rt", stdin);
#endif

    while( scanf("%d %d %d %d",&N,&M,&C,&K)==4 ){
        if( N==0 && M==0 && C==0 && K==0 )break;
        Read();
        Proc();
    }

    return 0;
}


